﻿using Styx;
using Styx.Common;
using Styx.CommonBot.Routines;

namespace RestoArenaHelper
{
    internal partial class RestoArenaHelper : CombatRoutine
    {
        public override string Name
        {
            get { return "Resto Arena Helper"; }
        }

        public override WoWClass Class
        {
            get { return WoWClass.Druid; }
        }

        public override bool WantButton
        {
            get { return true; }
        }

        public override void OnButtonPress()
        {
            Logging.Write("Config opened!");
            new newRestoArenaHelperConfig().ShowDialog();
        }

        public override void Pulse()
        {
            if (!StyxWoW.IsInGame || !StyxWoW.IsInWorld)
                return;
            if (StyxWoW.Me.IsDead)
                return;
            if (StyxWoW.Me.HasAura("Prowl"))
                return;
            UpdateContext();
            if (WoWContext.Battleground == CurrentWoWContext)
            {
                PVP();
                return;
            }
            if (WoWContext.Instances == CurrentWoWContext)
            {
                PVE();
                return;
            }
        }

        public void PVE()
        {
            CachedUnits.Pulse();
            HealManager.PulseHealManager();
            if ((HealManager.Tank.HasMyAura("Lifebloom") &&
                 Spell.GetAuraTimeLeft("Lifebloom", HealManager.Tank) < 3) ||
                Spell.LifebloomStackCount(HealManager.Tank) < 3)
                if (Spell.Cast("Lifebloom", HealManager.Tank))
                    return;
            if (HealManager.RejuTarget != null)
                if (HealManager.RejuTarget.HealthPercent <= RestoArenaHelperSettings.Instance.PveRejuvenationHealth)
                    if (Spell.Cast("Rejuvenation", HealManager.RejuTarget))
                        return;
        }

        public void PVP()
        {
            CachedUnits.Pulse();
            HealManager.PulseHealManager();
            if (!StyxWoW.Me.Combat)
                if ((HealManager.HealTarget.HasMyAura("Lifebloom") &&
                     Spell.GetAuraTimeLeft("Lifebloom", HealManager.HealTarget) < 3) ||
                    Spell.LifebloomStackCount(HealManager.HealTarget) < 3)
                    if (Spell.Cast("Lifebloom", HealManager.HealTarget))
                        return;
            if (StyxWoW.Me.HasAura("Preparation"))
                return;
            if (StyxWoW.Me.HasAura("Arena Preparation") && Spell.GetAuraTimeLeft("Arena Preparation", StyxWoW.Me) < 6)
                if ((StyxWoW.Me.HasMyAura("Lifebloom") &&
                     Spell.GetAuraTimeLeft("Lifebloom", StyxWoW.Me) < 3) ||
                    Spell.LifebloomStackCount(StyxWoW.Me) < 3)
                    if (Spell.Cast("Lifebloom", StyxWoW.Me))
                        return;
            if (StyxWoW.Me.HasAura("Arena Preparation"))
                return;
            if (HealManager.RejuTarget != null)
                if (Spell.Cast("Rejuvenation", HealManager.RejuTarget))
                    return;
        }

        public override void Initialize()
        {
            Logging.Write("Welcome to " + Name + " !");
            UpdateContext();
            HealManager.Initialize();
            CachedUnits.Initialize();
        }
    }
}